﻿using System;
using UnityEngine;
using UnityEngine.Events;
using Valve.VR;

// Token: 0x02000840 RID: 2112
public class SteamVR_TrackedObject : MonoBehaviour
{
	// Token: 0x060030D1 RID: 12497 RVA: 0x000FDD98 File Offset: 0x000FBF98
	private SteamVR_TrackedObject()
	{
		this.newPosesAction = SteamVR_Events.NewPosesAction(new UnityAction<TrackedDevicePose_t[]>(this.OnNewPoses));
	}

	// Token: 0x17000555 RID: 1365
	// (get) Token: 0x060030D2 RID: 12498 RVA: 0x000FDDB8 File Offset: 0x000FBFB8
	// (set) Token: 0x060030D3 RID: 12499 RVA: 0x000FDDC0 File Offset: 0x000FBFC0
	public bool isValid { get; private set; }

	// Token: 0x060030D4 RID: 12500 RVA: 0x000FDDCC File Offset: 0x000FBFCC
	private void OnNewPoses(TrackedDevicePose_t[] poses)
	{
		if (this.index == SteamVR_TrackedObject.EIndex.None)
		{
			return;
		}
		int num = (int)this.index;
		this.isValid = false;
		if (poses.Length <= num)
		{
			return;
		}
		if (!poses[num].bDeviceIsConnected)
		{
			return;
		}
		if (!poses[num].bPoseIsValid)
		{
			return;
		}
		this.isValid = true;
		SteamVR_Utils.RigidTransform rigidTransform = new SteamVR_Utils.RigidTransform(poses[num].mDeviceToAbsoluteTracking);
		if (this.origin != null)
		{
			base.transform.position = this.origin.transform.TransformPoint(rigidTransform.pos);
			base.transform.rotation = this.origin.rotation * rigidTransform.rot;
		}
		else
		{
			base.transform.localPosition = rigidTransform.pos;
			base.transform.localRotation = rigidTransform.rot;
		}
	}

	// Token: 0x060030D5 RID: 12501 RVA: 0x000FDEBC File Offset: 0x000FC0BC
	private void OnEnable()
	{
		SteamVR_Render instance = SteamVR_Render.instance;
		if (instance == null)
		{
			base.enabled = false;
			return;
		}
		this.newPosesAction.enabled = true;
	}

	// Token: 0x060030D6 RID: 12502 RVA: 0x000FDEF0 File Offset: 0x000FC0F0
	private void OnDisable()
	{
		this.newPosesAction.enabled = false;
		this.isValid = false;
	}

	// Token: 0x060030D7 RID: 12503 RVA: 0x000FDF08 File Offset: 0x000FC108
	public void SetDeviceIndex(int index)
	{
		if (Enum.IsDefined(typeof(SteamVR_TrackedObject.EIndex), index))
		{
			this.index = (SteamVR_TrackedObject.EIndex)index;
		}
	}

	// Token: 0x040030BF RID: 12479
	public SteamVR_TrackedObject.EIndex index;

	// Token: 0x040030C0 RID: 12480
	[Tooltip("If not set, relative to parent")]
	public Transform origin;

	// Token: 0x040030C2 RID: 12482
	private SteamVR_Events.Action newPosesAction;

	// Token: 0x02000841 RID: 2113
	public enum EIndex
	{
		// Token: 0x040030C4 RID: 12484
		None = -1,
		// Token: 0x040030C5 RID: 12485
		Hmd,
		// Token: 0x040030C6 RID: 12486
		Device1,
		// Token: 0x040030C7 RID: 12487
		Device2,
		// Token: 0x040030C8 RID: 12488
		Device3,
		// Token: 0x040030C9 RID: 12489
		Device4,
		// Token: 0x040030CA RID: 12490
		Device5,
		// Token: 0x040030CB RID: 12491
		Device6,
		// Token: 0x040030CC RID: 12492
		Device7,
		// Token: 0x040030CD RID: 12493
		Device8,
		// Token: 0x040030CE RID: 12494
		Device9,
		// Token: 0x040030CF RID: 12495
		Device10,
		// Token: 0x040030D0 RID: 12496
		Device11,
		// Token: 0x040030D1 RID: 12497
		Device12,
		// Token: 0x040030D2 RID: 12498
		Device13,
		// Token: 0x040030D3 RID: 12499
		Device14,
		// Token: 0x040030D4 RID: 12500
		Device15
	}
}
